<?php
/**
 * 原型模式
 * This file is part of pattern.
 * Author: tangzhou
 * Date: 2016/8/29
 * Time: 14:10
 * File: Prototype.php
 */

/**
 * 抽象原型类型
 * Class ProtoType
 */
abstract class ProtoType
{
    abstract function cloned();
}

/**
 * Class Plane
 */
class Plane extends ProtoType
{
    public $color;

    function fly()
    {
        echo "飞啊飞";
    }

    function cloned()
    {
        return clone $this;
    }
}

$p1 = new Plane();
$p1->fly();
$p1->color = 'blue';
$p2 = $p1->cloned();
$p2->color = 'red';
echo $p2->color.'-----'.$p1->color;
